package com.threaddemo6;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class NewSingleThreadScheduledExecutor {
    public static void main(String[] args) throws InterruptedException {
        ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();

        for (int i = 0; i < 10; i++) {
            ses.scheduleAtFixedRate(
                    ()-> System.out.println("执行 - " + Thread.currentThread().getName()),
                    0,//启动之后 多久开始执行
                    1,//每间隔多久执行
                    TimeUnit.SECONDS);//间隔时间单位
        }

        Thread.sleep(10 * 1000);

        ses.shutdown();


    }
}
